﻿Imports System.Data.SqlClient

Public Class TrangThaiDAO
    Public Shared Function Insert(ByVal tt As TrangThaiDTO) As Integer
        Dim str = String.Format("Insert into TrangThai(TrangThai) values (N'{0}')", tt.TrangThai)
        Dim connect As SqlConnection = DataProvider.ConnectDB("QuanLyHangHoa")
        connect.Open()
        Dim cmd As New SqlCommand(str, connect)
        cmd.CommandType = CommandType.Text
        Dim result As Integer = 1
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            result = 0
        End Try

        Return result
    End Function

    Public Shared Function Delete(ByVal maTT As String) As Integer
        Dim result As Integer = 1
        Dim StrSql As String
        StrSql = "Delete from TRANGTHAI where MaTT = '" & maTT & "'"
        Try
            SQLProvider.ExecNoneQuery(StrSql)
        Catch ex As Exception
            result = 0
        End Try
        Return result
    End Function

    Public Shared Function Update(ByVal tt As TrangThaiDTO) As Integer
        Dim result As Integer = 1
        Dim StrSql As String
        StrSql = "Update TRANGTHAI set TenTT = N'" & tt.TrangThai & "'"
        Try
            SQLProvider.ExecNoneQuery(StrSql)
        Catch ex As Exception
            result = 0
        End Try
        Return result
    End Function

    Public Shared Function Select_All() As DataTable
        Dim dt As DataTable
        Dim StrSql As String
        StrSql = "Select * from TRANGTHAI"
        dt = SQLProvider.ExecQuery(StrSql)
        Return dt
    End Function

    Public Shared Function Select_By_Ma(ByVal maTT As String) As DataTable
        Dim dt As DataTable
        Dim StrSql As String
        StrSql = "Select * from TRANGTHAI where MaTT = '" & maTT & "'"
        dt = SQLProvider.ExecQuery(StrSql)
        Return dt
    End Function

End Class
